<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<script>
/*
<p>闭包就是能够读取其他函数内部变量的函数</p>
<p>让这些变量的值始终保持在内存中。</p>
*/
function log(){
    var args = Array.prototype.slice.call(arguments);
    console.log.apply(console,args);
}
function f1(){
    var n=999;
    nAdd = function (){
        n+=1
    };
    function f2(){
        log(n);
    };
    return f2;
}
var result=f1();
result();
nAdd();
result();
var name = "The Window";
var object = {
    name : "My Object",
    getNameFunc : function(){
        return function(){
            return this.name;
        };
    }
};
log(window.object.getNameFunc()());
var object = {
    name : "My Object",
    getNameFunc : function(){
        var self = this;
        console.log(this);//Object
        return function(){
            console.log(this)//window
            return self.name;
        };
    }
};
log(window.object.getNameFunc()());
</script>
</body>
</html>
